package cn.codingjc.framework.common.core.status.model;

import cn.codingjc.framework.common.core.status.core.BaseStatus;
import cn.codingjc.framework.common.core.status.core.StatusMachine;

public enum PaymentStatus implements BaseStatus {

    /**
     * 无状态
     */
    EMPTY("EMPTY", "无状态"),

    /**
     * 初始化
     */
    INIT("INIT", "初始化"),
    /**
     * 支付中
     */
    PAYING("PAYING", "支付中"),
    /**
     * 支付成功
     */
    SUCCESS("SUCCESS", "支付成功"),
    /**
     * 支付失败
     */
    FAIL("FAIL", "支付失败"),

    ;

    private String status;
    private String desc;

    // 支付状态机内容
    private static final StatusMachine<PaymentStatus, PaymentEvent> STATUS_MECHINE = new StatusMachine<>();

    static {
        STATUS_MECHINE.accept(EMPTY, PaymentEvent.PAY_CREATE, INIT);
        STATUS_MECHINE.accept(INIT, PaymentEvent.PAY_PROCESS, PAYING);
        STATUS_MECHINE.accept(PAYING, PaymentEvent.PAY_SUCCESS, SUCCESS);
        STATUS_MECHINE.accept(PAYING, PaymentEvent.PAY_FAIL, FAIL);
    }

    PaymentStatus(String status, String desc) {
        this.status = status;
        this.desc = desc;
    }

    public static PaymentStatus getTargetStatus(PaymentStatus sourceStatus, PaymentEvent event) {
        return STATUS_MECHINE.getTargetStatus(sourceStatus, event);
    }
}
